home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue59 / Arch / Sample / UnitFormListBase.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-05-22  |  5.1 KB  |  179 lines

  1. unit UnitFormListBase;
  2. {
  3. When creating a new list sub-class from this form (using form inheritance --
  4. go to File|New..., choose the "CustomerOrders" tab, then choose this form) and
  5. override the abstract methods.
  6.  
  7.   procedure Initializeform; override;
  8.     This is where you do whatever initializations you need.
  9.  
  10.   procedure Finalizeform; override;
  11.     This is where you do whatever finalizations you need.
  12.  
  13.   procedure ClearWhereClause; virtual; // abstract
  14.     This is where you set the UI to its default settings.
  15.  
  16.   procedure UpdateWhereClause;
  17.     This is where you string together the where clause and assign it to the
  18.     associated object.
  19.  
  20.   procedure OpenNewEntity; override;
  21.     This is a little awkard: you have to fetch a new business object instance,
  22.     then use its ID to open the form. Once the form is open you free the local
  23.     reference to the newly created business object.
  24.  
  25.   function ObjectClass: TObjectBaseClass; override;
  26.       The ancestor uses this information to create an instance of the list's
  27.     associated ObjectList.
  28.  
  29.   function OpenSelectedFormType: TFormBaseClass; override;
  30.       The ancestor uses this information to open the form for the selected record.
  31.  
  32.   function SelectedKey: integer; override;
  33.     SelectedKey returns the key for the current record.
  34.  
  35.  
  36. Don't forget to add an action to open the list from UnitFormMain.
  37.  
  38. }
  39. interface
  40.  
  41. uses
  42.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  43.   StdCtrls, ExtCtrls, Menus, Db, Grids, DBGrids, ActnList, ComCtrls, ToolWin,
  44.   ImgList, UnitObjectBase, Buttons, UnitFormBase, UnitFrameResultSetBase;
  45.  
  46. type
  47.   TFormListBase = class;
  48.   TFormListBaseClass = class of TFormListBase;
  49.   TListSelectEvent = procedure(aFormList: TFormListBase) of object;
  50.  
  51.   TFormListBase = class(TFormBase)
  52.     PanelListBaseBottom: TPanel;
  53.     ButtonOkApply: TButton;
  54.     ButtonCancelClose: TButton;
  55.     PopupMenu: TPopupMenu;
  56.     ActionList: TActionList;
  57.     ActionApply: TAction;
  58.     ActionClose: TAction;
  59.     Open1: TMenuItem;
  60.     PanelListBaseClientBackground: TPanel;
  61.     ActionFind: TAction;
  62.     Find1: TMenuItem;
  63.     ToolBar1: TToolBar;
  64.     PanelFilter: TPanel;
  65.     BitBtnFind: TBitBtn;
  66.     BitBtn2: TBitBtn;
  67.     ToolButton1: TToolButton;
  68.     ToolButton4: TToolButton;
  69.     PanelListBaseApplyClose: TPanel;
  70.     PanelListBaseGridBackground: TPanel;
  71.     StatusBarAbstract: TStatusBar;
  72.     ButtonListBaseApply: TButton;
  73.     ButtonListBaseClose: TButton;
  74.     ToolButton2: TToolButton;
  75.     ToolButton3: TToolButton;
  76.     ActionOpen: TAction;
  77.     procedure ActionApplyExecute(Sender: TObject);
  78.     procedure ActionFindExecute(Sender: TObject);
  79.     procedure ActionCloseExecute(Sender: TObject);
  80.     procedure ActionOpenExecute(Sender: TObject);
  81.     procedure ActionOpenUpdate(Sender: TObject);
  82.   private
  83.     FOnListSelect: TListSelectEvent;
  84.   protected
  85.     procedure Apply;
  86.     procedure Initializeform; override;
  87.     procedure ClearWhereClause; virtual; // abstract
  88.     function GetFrameResultSet: TFrameResultSetBase; virtual; abstract;
  89.   public
  90.     property OnListSelect: TListSelectEvent read FOnListSelect write FOnListSelect;
  91.     function ShowModalPickListOKCancel: integer;
  92.     function ShowModalPickListApplyClose: integer;
  93.   end;
  94.  
  95. implementation
  96.  
  97. {$R *.DFM}
  98.  
  99. var ClassVariableListOfSingletonLists: TList;
  100.  
  101. { TFormList }
  102.  
  103. procedure TFormListBase.Apply;
  104. begin
  105.   if Assigned(OnListSelect)
  106.     then OnListSelect(Self);
  107. end;
  108.  
  109. //------------------------------------------------------------------------------
  110. function TFormListBase.ShowModalPickListApplyClose: integer;
  111. begin
  112.   ActionApply.Caption := 'Apply';
  113.   ButtonOkApply.ModalResult := mrNone;
  114.   ButtonCancelClose.Caption := 'Close';
  115.   PanelListBaseBottom.Visible := TRUE;
  116.   StatusBarAbstract.SizeGrip := FALSE;
  117.   Result := Self.ShowModal;
  118. end;
  119.  
  120. function TFormListBase.ShowModalPickListOKCancel: integer;
  121. begin
  122.   ActionApply.Caption := 'OK';
  123.   ButtonOkApply.ModalResult := mrOK;
  124.   ButtonCancelClose.Caption := 'Cancel';
  125.   StatusBarAbstract.SizeGrip := FALSE;
  126.   PanelListBaseBottom.Visible := TRUE;
  127.   Result := Self.ShowModal;
  128. end;
  129. //------------------------------------------------------------------------------
  130.  
  131. procedure TFormListBase.ActionApplyExecute(Sender: TObject);
  132. begin
  133.   inherited;
  134.   Apply;
  135. end;
  136.  
  137. procedure TFormListBase.Initializeform;
  138. begin
  139.   inherited;
  140. end;
  141.  
  142. procedure TFormListBase.ActionFindExecute(Sender: TObject);
  143. begin
  144.   inherited;
  145.   GetFrameResultSet.ResultSetObject.RefreshResultSet;
  146. end;
  147.  
  148. procedure TFormListBase.ClearWhereClause;
  149. begin
  150. end;
  151.  
  152. procedure TFormListBase.ActionCloseExecute(Sender: TObject);
  153. begin
  154.   inherited;
  155.   ModalResult := mrCancel;
  156. end;
  157.  
  158. procedure TFormListBase.ActionOpenExecute(Sender: TObject);
  159. begin
  160.   inherited;
  161.   GetFrameResultSet.OpenEntityForm;
  162. end;
  163.  
  164. procedure TFormListBase.ActionOpenUpdate(Sender: TObject);
  165. begin
  166.   inherited;
  167.   ActionOpen.Enabled := not(GetFrameResultSet.ResultSetObject.IsEmpty);
  168. end;
  169.  
  170. initialization
  171.  
  172.   ClassVariableListOfSingletonLists := TList.Create;
  173.  
  174. finalization
  175.  
  176.   ClassVariableListOfSingletonLists.Free;
  177.  
  178. end.
  179.